//
//  ViewController.m
//  Masonry-Exploration
//
//  Created by John on 2018/5/2.
//  Copyright © 2018年 HR Inc. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"
#import "Calculator.h"
#import "NSObject+hr_calculate.h"

@interface ViewController ()
@property (strong, nonatomic)  UIButton *btn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    _btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btn setTitle:@"calculate" forState:UIControlStateNormal];
    [_btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    _btn.layer.cornerRadius = 1.0f;
    _btn.layer.borderWidth = 1.0f;
    _btn.layer.borderColor = [UIColor redColor].CGColor;
    
   // _btn.frame = CGRectMake(50, 50, 100, 20);
    
   // subView.top = superView.top * 1 + 50
    _btn.translatesAutoresizingMaskIntoConstraints = NO; //使用AutoLayout必须设置为NO，否则报错
    
#pragma mark - NSLayoutConstraint约束使用
    
    [self.view addSubview:_btn];
    
    NSLayoutConstraint *topConstrait = [NSLayoutConstraint constraintWithItem:_btn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:50];
   
    NSLayoutConstraint *leftConstrait = [NSLayoutConstraint constraintWithItem:_btn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:50];
   
    NSLayoutConstraint *rightConstrait = [NSLayoutConstraint constraintWithItem:_btn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:-250];
    
    NSLayoutConstraint *bottomConstrait = [NSLayoutConstraint constraintWithItem:_btn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-450];

    [self.view addConstraints:[NSArray arrayWithObjects:topConstrait,bottomConstrait,leftConstrait,rightConstrait, nil]];
    
#pragma mark - Masonry
    
//    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.view).offset(50);
//        make.left.mas_equalTo(self.view.mas_left).offset(50);
//        make.right.mas_equalTo(self.view).offset(-250);
//        make.bottom.mas_equalTo(self.view).offset(-450);
//    }];
    
    
}
#pragma mark - 链式编程实现

-(void)btnClick:(UIButton *)btn
{
    int result = [Calculator hr_calculate:^(Calculator *cal) {
        cal.add(2);
        cal.minus(1).add(2);
    }];
    NSLog(@"%d",result);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

//
